home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-20 | 4.2 KB | 167 lines | [TEXT/CWIE] |
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CPopupMenuTracker.cp
- //
-
- #include "ocheaders.h"
- #include "FnAssert.h"
- #include "CPopupMenuTracker.h"
-
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // Private Data Structures & constants
- //
-
- union Converter
- {
- struct
- {
- short hiWd, loWd;
- } shortVal;
- long message;
- };
-
- const short bulletMark = 165; // char code 165 = bullet mark in most fonts
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CPopupMenuTracker::CPopupMenuTracker
- //
-
- CPopupMenuTracker::CPopupMenuTracker( CPopupMenuControl * control,
- MenuHandle itsMenu,
- short currentItemNumber,
- short fontID,
- short fontSize)
- {
- ASSERT((control!= NULL), "NULL control in temporary popup!");
-
- mControl = control;
- mMenu = itsMenu;
- mCurrentItem.itemNumber = currentItemNumber;
- mFontID = fontID;
- mFontSize = fontSize;
-
- // AcquirePort();
-
- if (::CountMItems(itsMenu) > 0)
- ::CalcMenuSize(itsMenu);
-
- if (mMenu)
- ::InsertMenu(mMenu, hierMenu);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CPopupMenuTracker::CPopupMenuTracker
- //
-
- CPopupMenuTracker::CPopupMenuTracker( CPopupMenuControl * control,
- MenuHandle itsMenu,
- short currentItemNumber)
- {
- mControl = control;
- mMenu = itsMenu;
- mCurrentItem.itemNumber = currentItemNumber;
- mFontID = geneva;
- mFontSize = 9;
-
- if (::CountMItems(itsMenu) > 0)
- ::CalcMenuSize(itsMenu);
-
- if (mMenu)
- ::InsertMenu(mMenu, hierMenu);
-
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CPopupMenuTracker::~CPopupMenuTracker
- //
-
- CPopupMenuTracker::~CPopupMenuTracker()
- {
- if (mMenu)
- {
- short theMenuID = (*mMenu)->menuID;
- ::DeleteMenu(theMenuID);
- }
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CPopupMenuTracker::TrackMouse
- //
-
- short CPopupMenuTracker::TrackMouse(Point& theMouse)
- {
- if (mMenu)
- {
- // Note: we're assuming theMouse is in global coordinates, so theres
- // no need to call ::LocalToGlobal(&theMouse);
-
- short savedFontFamily = LMGetSysFontFam(); //%BD jdo 28oct96 modified to live in Copland world
- short savedFontSize = LMGetSysFontSize(); //%BD jdo 28oct96 ditto
-
- // set up for our work:
- LMSetSysFontFam(mFontID); //%BD jdo 28oct96 set font ID - using supported API
- LMSetSysFontSize(mFontSize); //%BD jdo 28oct96 set font size - using supported API
- LMSetLastSPExtra( -1); //%BD jdo 28oct96 forces the font manager to re-cache the sysfont & size - use supported API
-
- SetItemMark(mMenu, mCurrentItem.itemNumber, bulletMark);
-
- Converter menuResult;
- menuResult.message = PopUpMenuSelect(mMenu, theMouse.v, theMouse.h, mCurrentItem.itemNumber);
-
- SetItemMark(mMenu, mCurrentItem.itemNumber, noMark);
-
- // put things back the way we found them:
- LMSetSysFontFam(savedFontFamily); //%BD jdo 28oct96 modified to live in Copland world
- LMSetSysFontSize(savedFontSize); //%BD jdo 28oct96 ditto
- LMSetLastSPExtra( -1); //%BD jdo 28oct96 forces the font manager to re-cache the sysfont & size - use supported API
-
- if (menuResult.shortVal.loWd)
- mCurrentItem.itemNumber = menuResult.shortVal.loWd;
- }
-
- return mCurrentItem.itemNumber;
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CPopupMenuTracker::GetCurrentItem
- //
-
- void CPopupMenuTracker::GetCurrentItem(CMenuItem * menuItem)
- {
- ASSERT(menuItem != NULL, "Null menu item object in CPopupMenuTracker::GetCurrentItem");
-
- menuItem->itemNumber = GetCurrentItemNumber();
- strcpy(menuItem->itemText, GetCurrentItemText());
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CPopupMenuTracker::GetCurrentItemNumber
- //
-
- short CPopupMenuTracker::GetCurrentItemNumber(void)
- {
- return mCurrentItem.itemNumber;
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- //
- // CPopupMenuTracker::GetCurrentItemText
- //
-
- char * CPopupMenuTracker::GetCurrentItemText(void)
- {
- ::GetItem(mMenu, mCurrentItem.itemNumber, ((StringPtr)mCurrentItem.itemText));
- p2cstr(((StringPtr)mCurrentItem.itemText));
-
- return mCurrentItem.itemText;
- }
-